﻿using BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Loginter.承运单管理
{
    public partial class JieShouQianShouCarriers : System.Web.UI.Page
    {
        CarrierBLL carbll = new CarrierBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                getProcCarr();
            }
        }

        /// <summary>
        /// 存储过程查询
        /// </summary>
        private void getProcCarr()
        {
            int TotalCount;
            string id = txt_CarriersID.Text.Trim();
            string name = dateinput.Value.Trim();
            string SendName = dateinput.Value.Trim();
            string startTime = string.Empty;
            string endTime = string.Empty;
            if (!string.IsNullOrWhiteSpace(dateinput.Value))
            {
                startTime = dateinput.Value;
            }
            if (!string.IsNullOrWhiteSpace(dateinput.Value))
            {
                endTime = dateinput.Value;
            }
            repter_carries.DataSource = carbll.GetPagesCarriers(id, name, SendName, startTime, endTime, TruckPager.CurrentPageIndex, TruckPager.PageSize, out TotalCount);
            TruckPager.RecordCount = TotalCount;
            repter_carries.DataBind();
        }

        protected void brn_select_Click(object sender, EventArgs e)
        {
            getProcCarr();
        }

        protected void TruckPager_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            TruckPager.CurrentPageIndex = e.NewPageIndex;
            getProcCarr();
        }

        protected void repter_carries_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            int id = Convert.ToInt32(e.CommandArgument);
            if (e.CommandName == "select")
            {
                Server.Transfer("CarriersXiangQing.aspx?id=" + id);
            }
            if (e.CommandName == "update")
            {
                int rest = carbll.ReceiveAccept(id);
                if (rest > 0)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('签收成功！');</script>");
                }
                else if (rest == -1)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('您已签收，请勿重复操作！');</script>");
                }
                else
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "<script>alert('签收失败！');</script>");
                }
            }
        }
    }
}